package com.slipper.system.common;

import com.slipper.common.exception.NotLoginException;
import com.slipper.common.util.GsonUtil;
import com.slipper.common.util.GzipUtil;

public class Constants extends com.slipper.common.constants.Constants {
    public static void setCurrentUser(UserDetail userDetail) {
        String json = GsonUtil.toJson(userDetail);
        String compressStr = GzipUtil.compress(json);
        getCurrentRequest().getSession().setAttribute(CURRENT_EMPLOYEE_SESSION, compressStr);
    }

    public static UserDetail getCurrentUser() {
        String json = (String) getCurrentRequest().getSession().getAttribute(CURRENT_EMPLOYEE_SESSION);
        if (json != null && !json.isEmpty()) {
            return GsonUtil.fromJson(GzipUtil.uncompress(json), UserDetail.class);
        } else {
            throw new NotLoginException();
        }
    }
}
